package com.student.course.repository;

import com.student.common.entity.Course;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * 课程数据访问接口
 * 
 * @author student
 * @date 2025
 */
@Repository
public interface CourseRepository extends JpaRepository<Course, String> {
    
    /**
     * 根据条件查询课程
     */
    @Query("SELECT c FROM Course c WHERE " +
           "(:courseName IS NULL OR c.courseName LIKE %:courseName%) AND " +
           "(:department IS NULL OR c.department LIKE %:department%) AND " +
           "(:courseType IS NULL OR c.courseType LIKE %:courseType%) AND " +
           "(:courseId IS NULL OR c.courseId LIKE %:courseId%) AND " +
           "(:status IS NULL OR c.status = :status)")
    Page<Course> findByConditions(@Param("courseName") String courseName, 
                                 @Param("department") String department, 
                                 @Param("courseType") String courseType,
                                 @Param("courseId") String courseId,
                                 @Param("status") String status,
                                 Pageable pageable);
    
    /**
     * 根据教师ID查询课程
     */
    Page<Course> findByTeacherId(String teacherId, Pageable pageable);
}
